import { Directive, ElementRef, inject } from '@angular/core';
import { LocalStorageService } from '../services/local-storage.service';
import { LOCAL_KEY_PERMISSION } from '../services/ServiceConstant';

@Directive({
  selector: '[sunshine-permission]',
  standalone: true
})
export class SunshinePermissionDirective {

  private local: LocalStorageService = inject(LocalStorageService);

  constructor(el: ElementRef) {

    // el.nativeElement.style.display = 'none';

    let permission = el.nativeElement.getAttribute('permission')
    console.log(permission)
    let permissionArray = this.local.get(LOCAL_KEY_PERMISSION);
    console.log(permissionArray)
    // if (!permission || !permissionStr || !JSON.parse(permissionStr!).contain(permission)) {
    //   // 不显示
    //   // el.nativeElement.style.display = 'none';
    // } else {
    //   el.nativeElement.style.display = 'none';
    // }
    if (permissionArray?.includes(permission)) {

    } else {
      el.nativeElement.style.display = 'none';
      console.log("888888888888888")
    }
  }

}
